<template>
  <div>
    <el-tabs :tab-position="tabPosition">
      <el-tab-pane label="用户管理">
        <el-form ref="form" :rules="rules" :model="form" label-width="300px">
          <el-form-item
            label="新品首发栏目商品显示数量"
            prop="litemall_wx_index_new"
          >
            <el-input
              v-model="form.litemall_wx_index_new"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item
            label="人气推荐栏目商品显示数量"
            prop="litemall_wx_index_hot"
          >
            <el-input
              v-model="form.litemall_wx_index_hot"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item
            label="品牌制造商直供栏目品牌商显示数量"
            prop="litemall_wx_index_brand"
          >
            <el-input
              v-model="form.litemall_wx_index_brand"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item
            label="专题精选栏目显示数量"
            prop="litemall_wx_index_topic"
          >
            <el-input
              v-model="form.litemall_wx_index_topic"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item label="分类栏目显示数量" prop="litemall_wx_catlog_list">
            <el-input
              v-model="form.litemall_wx_catlog_list"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item
            label="分类栏目商品显示数量"
            prop="litemall_wx_catlog_goods"
          >
            <el-input
              v-model="form.litemall_wx_catlog_goods"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button @click="nono('form')" size="mini">取消</el-button>
            <el-button type="primary" @click="updates('form')" size="mini"
              >确定</el-button
            >
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="其他配置">
        <el-form label-width="300px">
          <el-form-item label="商品分享功能">
            <el-switch v-model="form.litemall_wx_share"> </el-switch>
          </el-form-item>
          <el-form-item>
            <el-button @click="nono('form')" size="mini">取消</el-button>
            <el-button type="primary" @click="updates('form')" size="mini"
              >确定</el-button
            >
          </el-form-item>
        </el-form>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { getList, update } from "@/api/configuration/procedure";
export default {
  data() {
    return {
      tabPosition: "left",
      form: {},
      rules: {
        litemall_wx_index_new: [
          { required: true, message: "不能为空", trigger: "blur" },
        ],
        litemall_wx_index_hot: [
          { required: true, message: "不能为空", trigger: "blur" },
        ],
        litemall_wx_index_brand: [
          { required: true, message: "不能为空", trigger: "blur" },
        ],
        litemall_wx_index_topic: [
          { required: true, message: "不能为空", trigger: "blur" },
        ],
        litemall_wx_catlog_list: [
          { required: true, message: "不能为空", trigger: "blur" },
        ],
        litemall_wx_catlog_goods: [
          { required: true, message: "不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getdata();
  },
  methods: {
    // 数据获取
    getdata() {
      getList().then((res) => {
        console.log(res);
        this.form = res.data;
        this.form.litemall_wx_share =
          this.form.litemall_wx_share == "true" ? true : false;
      });
    },
    //数据更新
    updates(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          update(this.form).then((res) => {
            if (res.errmsg == "成功") {
              this.$notify({
                title: "成功",
                message: "小程序配置成功",
                type: "success",
              });
              this.getdata();
            }
          });
        }
      });
    },
    //取消
    nono(formName) {
      this.$refs[formName].resetFields();
      this.getdata();
    },
  },
};
</script>

<style lang="scss" scoped>
</style>